package com.example.userprovider.controller;

import com.example.userprovider.dto.AuthLoginDto;
import com.example.userprovider.service.AbstractLogin;
import com.example.userprovider.service.ILogin;
import org.example.api.R;
import org.example.exception.ValidException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录
 * @author
 * @date 2021-4-16 13:15
 */
@RestController
public class LoginController {

    @PostMapping(value = "/login")
    public R login(@RequestBody @Validated AuthLoginDto dto, BindingResult bindingResult) {
        dto.validData(bindingResult);
        ILogin login = AbstractLogin.loginMap.get(dto.getLoginType());
        if(login == null) {
            throw new ValidException("不支持此种类型登录");
        }
        return login.doLogin(dto);
    }
}
